<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
	$tuilogid=intval($_RQ['tuilogid']);
	if(!$tuilogid && intval($_RQ['orderid'])){
		$ordersn=pdo_getcolumn('jy_weishop_order',array('id'=>$_RQ['orderid'],'uniacid'=>$_SESSION['uniacid']),'ordersn');
		$tuilogid=pdo_getcolumn('jy_newcar_order',array('ordersn'=>$ordersn,'uniacid'=>$_SESSION['uniacid']),'tuilogid');
	}
	if($tuilogid){
		$tuilog=pdo_get('jy_newcar_tuilog',array('id'=>$tuilogid,'uniacid'=>$_SESSION['uniacid'],'type'=>1));
	}
	$tuilog['statustitle']=$this->tuilog_status[$tuilog['status']];	
	$tuilog['createtime']=$tuilog['starttime']?date('Y-m-d',$tuilog['starttime']):'无';
	$tuilog['endtime']=$tuilog['endtime']?date('Y-m-d H:i',$tuilog['endtime']):'';
	$return['tuilog']=$tuilog;
	$params=array('tuilogid'=>$tuilogid?:-1,'uniacid'=>$_SESSION['uniacid']);
	$return['params']=$params;
	set_html('title',$tuilog['sn'].'推广组详情');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['tuilogid']){
		$params['tuilogid']=$_RQ['tuilogid'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('order',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$item['member']=cfc('core')->member_show($item['mid']);
		$orderid=pdo_getcolumn('jy_weishop_order',array('ordersn'=>$item['ordersn'],'uniacid'=>$_SESSION['uniacid']),'id');
		$orderstatus=pdo_getcolumn('jy_weishop_order',array('ordersn'=>$item['ordersn'],'uniacid'=>$_SESSION['uniacid']),'status');
		$ordergoods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$orderid,'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
		$merchs =array();
		$item['feemoney']=0;
		foreach($ordergoods as &$gv){
			$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','marketprice','unit','image','title','merchid','weight'));
			$goodsinfo['total']=$gv['total'];
			$goodsinfo['price']=$gv['price'];
			$goodsinfo['image']=$goodsinfo['image']?tomedia($goodsinfo['image']):'';
			$goodsinfo['weight']=$goodsinfo['weight']>0?$goodsinfo['weight']:pdo_getcolumn('jy_weishop_goods_dispatch',array('goodsid'=>$gv['goodsid']),'weight');
			//获取门店
			$stores = array();
			$goodsinfo['storeids'] = json_decode($goodsinfo['storeids'],true);
			if ($goodsinfo['isverify'] == 1) {
				if (empty($goodsinfo['storeids'])) {
					$stores = pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>array(2,3)));
				}else {
					foreach($goodsinfo['storeids'] as $sv){
						$stores[]= pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>array(2,3),'id'=>$sv['id']));
					}
				}
			}elseif($shopset['openstore'] ==1){
				if (empty($goodsinfo['storeids'])) {
					$stores = pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
				}else {
					foreach($goodsinfo['storeids'] as $sv){
						$stores[]= pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'id'=>$sv['id']));
					}
				}
			}
			$goodsinfo['store']=$stores;
			//商品规格
			if($gv['optionid']){
				$specs=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$gv['optionid']),'specs');
				$specs=explode("_",$specs);
				foreach($specs as &$spec){
					$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
				}
				$goodsinfo['selespename']=implode("，",$specs);
			}
			$gv=$goodsinfo;
		}
		$item['goods']=$ordergoods;
		$item['statustitle']=$this->order_status[$orderstatus];	
		$item['createtime']=date('Y-m-d H:i',$item['createtime']);
		$item['endtime']=$item['endtime']?date('Y-m-d H:i',$item['endtime']):'';
		$item['tuifee']=$this->sum('commission',array('ordersn'=>$item['ordersn'],'mid'=>$item['agent_id'],'uniacid'=>$_SESSION['uniacid'],'type'=>1),'money');
		$item['allfee']=price($item['tuifee']+$item['qifee']);
	}
	exi($list);
}
?>